package com.sunda.spmsorder.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sunda.spmsorder.entity.OrderCostDept;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 订单费用承担部门 Mapper 接口
 * </p>
 *
 * @author Wayne
 * @since 2021-04-20
 */
@Mapper
public interface OrderCostDeptMapper extends BaseMapper<OrderCostDept> {

    @Select("SELECT C1.DEPT_ID AS \"deptIdL1\", C1.DEPT_NAME AS \"deptNameL1\", C1.SUPERIOR_DEPT AS \"superiorDeptL1\",\n" +
            "       C2.DEPT_ID AS \"deptIdL2\", C2.DEPT_NAME AS \"deptNameL2\", C2.SUPERIOR_DEPT AS \"superiorDeptL2\",\n" +
            "       C3.DEPT_ID AS \"deptIdL3\", C3.DEPT_NAME AS \"deptNameL3\", C3.SUPERIOR_DEPT AS \"superiorDeptL3\",\n" +
            "       C4.DEPT_ID AS \"deptIdL4\", C4.DEPT_NAME AS \"deptNameL4\", C4.SUPERIOR_DEPT AS \"superiorDeptL4\",\n" +
            "       C5.DEPT_ID AS \"deptIdL5\", C5.DEPT_NAME AS \"deptNameL5\", C5.SUPERIOR_DEPT AS \"superiorDeptL5\",\n" +
            "       C6.DEPT_ID AS \"deptIdL6\", C6.DEPT_NAME AS \"deptNameL6\", C6.SUPERIOR_DEPT AS \"superiorDeptL6\",\n" +
            "       C7.DEPT_ID AS \"deptIdL7\", C7.DEPT_NAME AS \"deptNameL7\", C7.SUPERIOR_DEPT AS \"superiorDeptL7\"\n" +
            "FROM ORDER_COST_DEPT C1\n" +
            "    LEFT JOIN ORDER_COST_DEPT C2 ON C2.SUPERIOR_DEPT = C1.DEPT_ID\n" +
            "    LEFT JOIN ORDER_COST_DEPT C3 ON C3.SUPERIOR_DEPT = C2.DEPT_ID\n" +
            "    LEFT JOIN ORDER_COST_DEPT C4 ON C4.SUPERIOR_DEPT = C3.DEPT_ID\n" +
            "    LEFT JOIN ORDER_COST_DEPT C5 ON C5.SUPERIOR_DEPT = C4.DEPT_ID\n" +
            "    LEFT JOIN ORDER_COST_DEPT C6 ON C6.SUPERIOR_DEPT = C5.DEPT_ID\n" +
            "    LEFT JOIN ORDER_COST_DEPT C7 ON C7.SUPERIOR_DEPT = C6.DEPT_ID\n" +
            "WHERE C1.SUPERIOR_DEPT = 0\n" +
            "ORDER BY C1.DEPT_ID, C2.DEPT_ID, C3.DEPT_ID ASC")
    List<Map<String, Object>> getOrderCostDeptLevel();
}
